home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / inetutil.1 / inetutil / inetutils-1.1 / talk / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-22  |  5.1 KB  |  196 lines

  1. /*
  2.  * Copyright (c) 1983, 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. static char sccsid[] = "@(#)display.c    8.1 (Berkeley) 6/6/93";
  36. #endif /* not lint */
  37.  
  38. /*
  39.  * The window 'manager', initializes curses and handles the actual
  40.  * displaying of text
  41.  */
  42.  
  43. #ifdef HAVE_CONFIG_H
  44. #include <config.h>
  45. #endif
  46.  
  47. #include "talk.h"
  48.  
  49. xwin_t    my_win;
  50. xwin_t    his_win;
  51. WINDOW    *line_win;
  52.  
  53. int    curses_initialized = 0;
  54.  
  55. /*
  56.  * max HAS to be a function, it is called with
  57.  * a argument of the form --foo at least once.
  58.  */
  59. max(a,b)
  60.     int a, b;
  61. {
  62.  
  63.     return (a > b ? a : b);
  64. }
  65.  
  66. /*
  67.  * Display some text on somebody's window, processing some control
  68.  * characters while we are at it.
  69.  */
  70. display(win, text, size)
  71.     register xwin_t *win;
  72.     register char *text;
  73.     int size;
  74. {
  75.     register int i;
  76.     char cch;
  77.  
  78.     for (i = 0; i < size; i++) {
  79.         if (*text == '\n') {
  80.             xscroll(win, 0);
  81.             text++;
  82.             continue;
  83.         }
  84.         /* erase character */
  85.         if (*text == win->cerase) {
  86.             wmove(win->x_win, win->x_line, max(--win->x_col, 0));
  87.             getyx(win->x_win, win->x_line, win->x_col);
  88.             waddch(win->x_win, ' ');
  89.             wmove(win->x_win, win->x_line, win->x_col);
  90.             getyx(win->x_win, win->x_line, win->x_col);
  91.             text++;
  92.             continue;
  93.         }
  94.         /*
  95.          * On word erase search backwards until we find
  96.          * the beginning of a word or the beginning of
  97.          * the line.
  98.          */
  99.         if (*text == win->werase) {
  100.             int endcol, xcol, i, c;
  101.  
  102.             endcol = win->x_col;
  103.             xcol = endcol - 1;
  104.             while (xcol >= 0) {
  105.                 c = readwin(win->x_win, win->x_line, xcol);
  106.                 if (c != ' ')
  107.                     break;
  108.                 xcol--;
  109.             }
  110.             while (xcol >= 0) {
  111.                 c = readwin(win->x_win, win->x_line, xcol);
  112.                 if (c == ' ')
  113.                     break;
  114.                 xcol--;
  115.             }
  116.             wmove(win->x_win, win->x_line, xcol + 1);
  117.             for (i = xcol + 1; i < endcol; i++)
  118.                 waddch(win->x_win, ' ');
  119.             wmove(win->x_win, win->x_line, xcol + 1);
  120.             getyx(win->x_win, win->x_line, win->x_col);
  121.             text++;
  122.             continue;
  123.         }
  124.         /* line kill */
  125.         if (*text == win->kill) {
  126.             wmove(win->x_win, win->x_line, 0);
  127.             wclrtoeol(win->x_win);
  128.             getyx(win->x_win, win->x_line, win->x_col);
  129.             text++;
  130.             continue;
  131.         }
  132.         if (*text == '\f') {
  133.             if (win == &my_win)
  134.                 wrefresh(curscr);
  135.             text++;
  136.             continue;
  137.         }
  138.         if (win->x_col == COLS-1) {
  139.             /* check for wraparound */
  140.             xscroll(win, 0);
  141.         }
  142.         if (*text < ' ' && *text != '\t') {
  143.             waddch(win->x_win, '^');
  144.             getyx(win->x_win, win->x_line, win->x_col);
  145.             if (win->x_col == COLS-1) /* check for wraparound */
  146.                 xscroll(win, 0);
  147.             cch = (*text & 63) + 64;
  148.             waddch(win->x_win, cch);
  149.         } else
  150.             waddch(win->x_win, *text);
  151.         getyx(win->x_win, win->x_line, win->x_col);
  152.         text++;
  153.     }
  154.     wrefresh(win->x_win);
  155. }
  156.  
  157. /*
  158.  * Read the character at the indicated position in win
  159.  */
  160. readwin(win, line, col)
  161.     WINDOW *win;
  162. {
  163.     int oldline, oldcol;
  164.     register int c;
  165.  
  166.     getyx(win, oldline, oldcol);
  167.     wmove(win, line, col);
  168.     c = winch(win);
  169.     wmove(win, oldline, oldcol);
  170.     return (c);
  171. }
  172.  
  173. /*
  174.  * Scroll a window, blanking out the line following the current line
  175.  * so that the current position is obvious
  176.  */
  177. xscroll(win, flag)
  178.     register xwin_t *win;
  179.     int flag;
  180. {
  181.  
  182.     if (flag == -1) {
  183.         wmove(win->x_win, 0, 0);
  184.         win->x_line = 0;
  185.         win->x_col = 0;
  186.         return;
  187.     }
  188.     win->x_line = (win->x_line + 1) % win->x_nlines;
  189.     win->x_col = 0;
  190.     wmove(win->x_win, win->x_line, win->x_col);
  191.     wclrtoeol(win->x_win);
  192.     wmove(win->x_win, (win->x_line + 1) % win->x_nlines, win->x_col);
  193.     wclrtoeol(win->x_win);
  194.     wmove(win->x_win, win->x_line, win->x_col);
  195. }
  196.